package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.core.example.BaseExample.E_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.E_MODIFIED_USER_ID;
import static org.jsola.core.example.BaseExample.N_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.N_MODIFIED_USER_ID;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_ABSENTEEISM_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_ABSENTEEISM_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_BUSINESS_COMMISSION;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_COMPANY_ID;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_EMP_ID;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_GMT_CREATE_END;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_GMT_CREATE_START;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_GMT_MODIFIED_END;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_GMT_MODIFIED_START;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LATE_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LATE_MINUTES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LATE_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LEAVE_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LEAVE_MINUTES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_LEAVE_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_MONTH;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_NUMBER;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_OTHERS_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_OTHERS_DED_REMARK;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_OVERALL_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_OVERALL_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_OVERTIME_PAY;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_PERSON_TAX_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_PF_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_REMARK;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_SOC_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_STATUS;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_SUBSIDY;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_SUPPLEMENT_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_SUPPLEMENT_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_TEAM_COMMISSION;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_UNCHECKED_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_UNCHECKED_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_WORKING_DAYS;
import static org.jsola.hr.example.AttendanceMonthlyExample.E_YEAR;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_ABSENTEEISM_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_ABSENTEEISM_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_BUSINESS_COMMISSION;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_COMPANY_ID;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_EMP_ID;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_GMT_CREATE_END;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_GMT_CREATE_START;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_GMT_MODIFIED_END;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_GMT_MODIFIED_START;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LATE_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LATE_MINUTES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LATE_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LEAVE_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LEAVE_MINUTES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_LEAVE_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_MONTH;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_NUMBER;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_OTHERS_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_OTHERS_DED_REMARK;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_OVERALL_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_OVERALL_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_OVERTIME_PAY;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_PERSON_TAX_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_PF_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_REMARK;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_SOC_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_STATUS;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_SUBSIDY;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_SUPPLEMENT_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_SUPPLEMENT_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_TEAM_COMMISSION;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_UNCHECKED_DED;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_UNCHECKED_TIMES;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_WORKING_DAYS;
import static org.jsola.hr.example.AttendanceMonthlyExample.N_YEAR;

/**
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AttendanceMonthlyQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_NUMBER, example = E_NUMBER)
    @Length(max = 32)
    private String number;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 32)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 32)
    private String month;

    @ApiParam(value = N_LATE_TIMES, example = E_LATE_TIMES)
    private Integer lateTimes;

    @ApiParam(value = N_LATE_DED, example = E_LATE_DED)
    private Integer lateDed;

    @ApiParam(value = N_LATE_MINUTES, example = E_LATE_MINUTES)
    private Integer lateMinutes;

    @ApiParam(value = N_LEAVE_TIMES, example = E_LEAVE_TIMES)
    private Integer leaveTimes;

    @ApiParam(value = N_LEAVE_DED, example = E_LEAVE_DED)
    private Integer leaveDed;

    @ApiParam(value = N_LEAVE_MINUTES, example = E_LEAVE_MINUTES)
    private Integer leaveMinutes;

    @ApiParam(value = N_ABSENTEEISM_TIMES, example = E_ABSENTEEISM_TIMES)
    private Integer absenteeismTimes;

    @ApiParam(value = N_ABSENTEEISM_DED, example = E_ABSENTEEISM_DED)
    private Integer absenteeismDed;

    @ApiParam(value = N_UNCHECKED_TIMES, example = E_UNCHECKED_TIMES)
    private Integer uncheckedTimes;

    @ApiParam(value = N_UNCHECKED_DED, example = E_UNCHECKED_DED)
    private Integer uncheckedDed;

    @ApiParam(value = N_SUPPLEMENT_TIMES, example = E_SUPPLEMENT_TIMES)
    private Integer supplementTimes;

    @ApiParam(value = N_SUPPLEMENT_DED, example = E_SUPPLEMENT_DED)
    private Integer supplementDed;

    @ApiParam(value = N_OVERALL_TIMES, example = E_OVERALL_TIMES)
    private Integer overallTimes;

    @ApiParam(value = N_OVERALL_DED, example = E_OVERALL_DED)
    private Integer overallDed;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_OTHERS_DED, example = E_OTHERS_DED)
    private Integer othersDed;

    @ApiParam(value = N_OTHERS_DED_REMARK, example = E_OTHERS_DED_REMARK)
    @Length(max = 255)
    private String othersDedRemark;

    @ApiParam(value = N_SOC_DED, example = E_SOC_DED)
    private Integer socDed;

    @ApiParam(value = N_PF_DED, example = E_PF_DED)
    private Integer pfDed;

    @ApiParam(value = N_PERSON_TAX_DED, example = E_PERSON_TAX_DED)
    private Integer personTaxDed;

    @ApiParam(value = N_WORKING_DAYS, example = E_WORKING_DAYS)
    private Integer workingDays;

    @ApiParam(value = N_TEAM_COMMISSION, example = E_TEAM_COMMISSION)
    private Integer teamCommission;

    @ApiParam(value = N_BUSINESS_COMMISSION, example = E_BUSINESS_COMMISSION)
    private Integer businessCommission;

    @ApiParam(value = N_OVERTIME_PAY, example = E_OVERTIME_PAY)
    private Integer overtimePay;

    @ApiParam(value = N_SUBSIDY, example = E_SUBSIDY)
    private Integer subsidy;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;

    @ApiParam(value = N_REMARK, example = E_REMARK)
    @Length(max = 255)
    private String remark;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public AttendanceMonthlyQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

